<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@taglib uri="/authtaglib" prefix="auth" %>
<!DOCTYPE html>
<html>
<head>
<title>人员管理</title>
<jsp:include page="/include.jsp"/>
<script type="text/javascript">
//执行查询
function doQuery() {
    if ($("#datasource_query_form").form("validate")) {
        $("#datagrid").datagrid('options').queryParams = serializeObject($('#datasource_query_form')); //把查询条件赋值给datagrid内部变量
        $("#datagrid").datagrid('load'); //重新加载
    }
}
//重置查询条件
function doReset() {
    $('#datasource_query_form').form('reset');
}
//页面加载完后响应 onReady
$(function () {
    //查询按纽绑定事件
    $('#btnQuery').bind('click', doQuery);
    //重置按纽绑定事件
    $('#btnReset').bind('click', doReset);
    //初始化主列表
    $('#datagrid').datagrid({
        url: '${pageContext.request.contextPath}/cnbdw/employeePunchHistoryAction!getAllDatasourceList.action',
        fit: true,
        border: false,
        fitColumns: true,
        pagination: true,
        pageList: [30],
        rownumbers: false,
        sortName: 'id',
        sortOrder: 'desc',
        striped: true,
        columns: [
            [
               // {field: 'id', title: 'id', align: 'left', formatter: function (value, rowData, rowIndex) {if (value == '') {return '--'} return value;}},
                {field: 'name', title: '姓名', align: 'left', formatter: function (value, rowData, rowIndex) {if (value == '') {return '--'} 
                	return getName(rowData.employee, $('#datagrid').datagrid('getData'));	}},
                	
                {field: 'cardType', title: '证件类型', align: 'left', formatter: function (value, rowData, rowIndex) {if (value == '') {return '--'} 
                	 var value=getCardType(rowData.employee, $('#datagrid').datagrid('getData'));	
                	  if (value == 1) {
                        return '身份证'
                    } else if(value == 2){
                        return '军官证'
                    }
                 }},
                	
                {field: 'cardNo', title: '证件号', align: 'left', formatter: function (value, rowData, rowIndex) {if (value == '') {return '--'} 
                		return getCardNo(rowData.employee, $('#datagrid').datagrid('getData'));	}},
                		
                {field: 'company', title: '单位', align: 'left', formatter: function (value, rowData, rowIndex) {if (value == '') {return '--'} 
                	return getCompany(rowData.employee, $('#datagrid').datagrid('getData'));	}},

                {field: 'punchMachNo', title: '登离舰读卡器号', align: 'left', formatter: function (value, rowData, rowIndex) {if (value == '') {return '--'} return value;}},
                {field: 'cardNum', title: '卡号', align: 'left', formatter: function (value, rowData, rowIndex) {if (value == '') {return '--'} return value;}},
                {field: 'punch', title: '上下船', align: 'left', formatter: function (value, rowData, rowIndex) {
                    if (value == 1) {
                        return '<span style="color:green;"><b>上船</b></span>'
                    } else{
                        return '<span style="color:red;"><b>下船</b></span>'
                    }
                    return value;
                }},
                {field: 'punchTime', title: '上下船时间', align: 'left', formatter: function (value, rowData, rowIndex) {if (value == '') {return '--'} return value;}}
            ]
        ],
        toolbar: '#datagrid_toobar'
    });
    
    $('#datasource_datsourcename').combobox({
            url:'${pageContext.request.contextPath}/employeeAction!getNameSelectData.action',
            valueField:'id',
            textField:'name',
            editable:false
        });
});

function showFileUpload(callbackId) {
    window.top.$('<div/>').dialog({
        href: '${pageContext.request.contextPath}/cnbdw/special/file_upload.jsp',
        modal: true,
        top: ($(window.top).height() - 400) * 0.5,
        left: ($(window.top).width() - 600) * 0.5,
        width: 400,
        title: '上传附件',
        buttons: [
            {
                text: '保存',
                iconCls: '',
                id: 'fileUploadDialog',
                handler: function () {
                    //获取专题性别参数
                    var d = window.top.$(this).closest('.window-body');
                    if (window.top.fileValidateData()) {
                        window.top.$('#fileUploadForm').form('submit', {
                            url: '${pageContext.request.contextPath}/fileUploadAction!uploadFile.action',
                            success: function (result) {
                                try {
                                    var r = $.parseJSON(result);
                                    if (r.err != null && r.err != '') {
                                        //显示提示信息
                                        $.messager.show({
                                            title: '提示',
                                            msg: r.err
                                        });
                                    } else {
                                        $('#' + callbackId).val(r.msg);
                                        //关闭新增窗口
                                        d.dialog('destroy');
                                    }
                                } catch (e) {
                                    $.messager.alert('提示', result);
                                }
                            }
                        });
                    }
                }
            }
        ],
        onClose: function () {
            window.top.$(this).dialog('destroy');
        }
    });
}


function getName(objInfo, data) {
    if(objInfo && objInfo.$ref){
        objInfos = jsonPath(data, objInfo.$ref);
        return objInfos[0].name;
    }
    if(objInfo != null){
        return objInfo.name;
    }
    return "--";
}
function getCompany(objInfo, data) {
    if(objInfo && objInfo.$ref){
        objInfos = jsonPath(data, objInfo.$ref);
        return objInfos[0].company;
    }
    if(objInfo != null){
        return objInfo.company;
    }
    return "--";
}
function getCardType(objInfo, data) {
    if(objInfo && objInfo.$ref){
        objInfos = jsonPath(data, objInfo.$ref);
        return objInfos[0].cardType;
    }
    if(objInfo != null){
        return objInfo.cardType;
    }
    return "--";
}
function getCardNo(objInfo, data) {
    if(objInfo && objInfo.$ref){
        objInfos = jsonPath(data, objInfo.$ref);
        return objInfos[0].cardNo;
    }
    if(objInfo != null){
        return objInfo.cardNo;
    }
    return "--";
}
</script>
</head>
<body class="easyui-layout">
<form id="datasource_query_form" method="post">
    <div data-options="region:'north'" style="height:60px;border-bottom:none;border-top:none;">
        <table border="0" cellpadding="0" cellspacing="0" height="100%" width="50%">
            <tr>
                <td style="width:1%;text-align:left;" nowrap="nowrap">
                    <label for="datasource_datsourcename">姓名：</label>
                </td>
                <td style="width:1%;text-align:left;" nowrap="nowrap">
                    <input type="text" id="datasource_datsourcename" name="empId" class="easyui-validatebox"
                           data-options="validType:'specialCharFilter'"/>&nbsp;&nbsp;
                </td>
                <td style="width:2%;text-align:left;" nowrap="nowrap">
                    <label >开始时间：</label>
                    <input id="start" name="start" type="text" class="easyui-datebox">&nbsp;
                     <label >结束时间：</label>
                    <input id="end" name="end" type="text" class="easyui-datebox">&nbsp;&nbsp;&nbsp;
                </td>
                <td colspan="2" style="width:10%;text-align:left;" nowrap="nowrap">
                    <input type="button" id="btnQuery" value="查 询" class="search_btn"/>
                    <input type="button" id="btnReset" value="重 置" class="reset_btn"/>
                </td>
            </tr>
        </table>
    </div>
    <div data-options="region:'center'" style="border-top:none">
        <table id="datagrid"></table>
    </div>
</form>
</body>
</html>

